package www.yingdi365.com.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import www.yingdi365.com.R;
import www.yingdi365.com.base.ZjbBaseActivity;

public class ChuangJianWXBActivity extends ZjbBaseActivity implements View.OnClickListener {

    private EditText editWeiXiangBenMC;
    private EditText editWeiXiangBenMS;
    private TextView textCount;
    private Button buttonBaoCun;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chuang_jian_wxb);
        init();
    }

    @Override
    protected void initSP() {

    }

    @Override
    protected void initIntent() {

    }

    @Override
    protected void findID() {
        editWeiXiangBenMC = (EditText) findViewById(R.id.editWeiXiangBenMC);
        editWeiXiangBenMS = (EditText) findViewById(R.id.editWeiXiangBenMS);
        textCount = (TextView) findViewById(R.id.textCount);
    }

    @Override
    protected void initViews() {
        ((TextView) findViewById(R.id.textViewTitle)).setText("创建微相本");
        buttonBaoCun = (Button) findViewById(R.id.buttonBaoCun);
    }

    @Override
    protected void setListeners() {
        findViewById(R.id.imageBack).setOnClickListener(this);
        buttonBaoCun.setOnClickListener(this);
        editWeiXiangBenMC.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                btnStatus();
            }
        });
        editWeiXiangBenMS.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                btnStatus();
                textCount.setText(s.length()+"/140");
            }
        });
    }

    private void btnStatus() {
        if (!TextUtils.isEmpty(editWeiXiangBenMC.getText().toString().trim())&&!TextUtils.isEmpty(editWeiXiangBenMS.getText().toString().trim())){
            buttonBaoCun.setEnabled(true);
        }else {
            buttonBaoCun.setEnabled(false);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.buttonBaoCun:
                Intent intent = new Intent();
                intent.setClass(this, BianJiWXBActivity.class);
                startActivity(intent);
                break;
            case R.id.imageBack:
                finish();
                break;
        }
    }
}
